/**
 * express.js 基本示例
 */

//导入Express模块
const express = require("express");
//导入cookie模块
const cookieParser = require("cookie-parser");
//创建Express应用
const app = express();
//Express http服务端口
const port = 3001;

app.use(express.json());
app.use(express.urlencoded({extended: false}));

app.use(cookieParser());

//http访问路径
app.get("/", function (req, res) {
    if(req.cookies.remember){
        res.send(`记住了。<a href="/forget">忘记</a>`)
    }else{
        let str = `
            <form method="post">
                <lable>
                    <input type="checkbox" name="remember"/>记住
                </lable>
                <input type="submit" value="提交"/>
            </from>        
        `;
        res.send(str);
    }
});

app.get("/forget",function(res,req){
    res.clearCookie("remember");
    res.redirect("back");
});

//启动Express服务
app.listen(port, function () {
    console.log(`MyApp访问地址:http://127.0.0.1:${port}`);
});